#include <QApplication>
#include <QDateTime>

#include <httpclient.h>
#include <qdebug.h>

void issues(const QString &owner, const QString &repo) {

    QString uri = QString("https://gitee.com/api/v5/repos/%1/%2/issues").arg(owner).arg(repo);
    Request req(uri);
    req.addQuery("state", "open");
    req.addQuery("sort", "created");
    req.addQuery("direction", "desc");
    req.addQuery("page", "1");
    req.addQuery("per_page", "20");

    HttpClient::instance().setAutoUserAgent(true);
    auto resp = HttpClient::instance().get(req);

    foreach (auto var, resp.toList()) {
        auto map = var.toMap();
        map.value("id").toInt();
        auto url = map.value("url").toString();
        auto html_url = map.value("html_url").toString();
        map.value("repository_url").toString();
        map.value("created_at").toString();
        auto issue_state = map.value("issue_state").toString();
        map.value("comments_url").toString();
        auto title = map.value("title").toString();

        qDebug() << QString("[%1] %2").arg(issue_state).arg(title);
        qDebug() << html_url;
    }
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QString owner, repo;
    owner = "GXDE-OS";
    repo = "GXDE";

    issues(owner, repo);

    return 0;
}
